<?php

class Nsd extends Controller {
    
	function setVars()
	{
		$this->tpl['title'] = "Welcome";
		$this->tpl['head'] = '';
        $this->tpl['body'] = '';
        $this->tpl['menu'] = '';
        $this->tpl['sidebar'] = '';
        
        # For Ajax
        $this->tpl['controller_url'] = site_url($this->uri->segment(1).'/'.$this->uri->segment(2)).'/';
        $this->tpl['tpljs'][]  = 'jquery';
        $this->tpl['tpljs'][]  = 'jquery.cookie';
        $this->tpl['tpljs'][]  = 'ShowHideInputFields';
	}
    
	function __construct() 
	{
		parent::Controller();
        $this->auth->CheckTaMeR(101);
		$this->setVars();
        //$this->load->model('Master_Model', 'mdb');
        //$this->load->library('profiler');
        $this->load->library('pquery');
	}
    
	
	function index()
	{
        $this->load->model('data_model','data');
        $nt = $this->data->getTreePreOrder($this->data->getNodeFromId('160'));
        $nt = $nt['result_array'];
        $note = $nt[0];
        unset($nt[0]);
        
        
        foreach($nt as $k=>$v){
            $options[$v['id']]=$v['name'];
        }
        $uri = site_url($this->uri->segment(1).'/'.$this->uri->segment(2)).'/';        
        $this->tpl['body'] .= '<form action="http://localhost/pzzazz.php/test/nsd/nsd_ajax" method="post">';
        $js=  $this->pquery->remote_function(array('update' => '#field', 'url' => $uri));
    $this->tpl['body'] .= form_dropdown("field",$options, FALSE, "onchange=change(this.value)").'<br />';
        foreach($nt as $k=>$v){
            if($v['data']) {
                $data[$v['id']]['id']= 'ShowHide';
                $data[$v['id']]['name']= $v['id'];
                $data[$v['id']]['value']=$v['data'];
                if($v['name'] != 'validator_list'){
                    $data[$v['id']]['size']= '8';
                }else{
                    $data[$v['id']]['size']= '80';
                }
            }
        }
        
        foreach($data as $k=>$v){
            if ($v['name'] != 191){
            	$this->tpl['body'] .= form_input($v);
            }else{
                unset($v['size']);
                
                $v['value'] = str_replace ('|', "\n", $v['value'], $count);
                $a= array("rows"=>14, "cols"=>25);
                $a = array_merge($a,$v);
                $this->tpl['body'] .= form_textarea($a);
            }
        }

        $this->tpl['body'] .= '<br /><input type="submit" />'; 
        $this->tpl['body'] .= '</form>'; 
        

        $this->load->view('blank',$this->tpl);
    }
    
    /**
    * @note	nsd_ajax
    * @info	This will unhide the input box for the selected field
    * @author	Dennis T. Kaplan
    *
    * @access	public
    * @param	array string mixed
    * @return	
    */	
    function nsd_ajax()
    {
        echo '<h4>Ajax Form Submitted Thanks</h4><br />Field :'.$this->input->post('field');
        echo $this->pquery->tag($this->pquery->alert($this->input->post('field')));
    }
    
    
	
}
?>
